<template>
	<view>
		<view class="navbar" style="height: 180rpx;background-color: #fff;padding: 20rpx;">
			<view class="title" style="font-weight: bold;font-size: 45rpx;text-align: center;color: #dd6161;">首页</view>
			<view class="search" style="width: 95%;margin: 20rpx auto;flex-shrink: 0;border: 2rpx solid #dd6161;
			border-radius: 50rpx;background-color: #f2f2f2;display: flex;flex-direction: row;justify-content: start;
			align-items: center;position: relative;height: 64rpx;">
				<u-icon name="search" style="margin-left: 20rpx;"></u-icon>
				<input type="text" placeholder="请输入关键字" style="margin-left: 20rpx;" v-model="value">
				<button @click="submit" class="bu" style="width: 120rpx;height: 95%;background-color: #fa3534;
				border-radius: 50rpx;position: absolute;right: 1rpx;top: 1rpx;">搜索</button>
			</view>
		</view>
		<view class="main">
			<scroll-view scroll-y="true" class="left">
				<view class="tab">
					<view class="tab-item" v-for="(item,index) in tabList" :class="activeIndex === index ? 'active' : ''"
					@click="tabChange(index)">
						{{item}}
					</view>
				</view>
			</scroll-view>
			<scroll-view scroll-y="true" class="right">
				<view class="cate">
					<view class="cate-item" v-for="item in cateList">
						<image :src="$baseUrl + item.imgUrl"></image>
						<text>{{item.serviceName}}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<u-popup class="popup" mode="bottom" v-model="show">
			<view class="cate">
				<view class="cate-item" v-for="item in searchList">
					<image :src="$baseUrl + item.imgUrl"></image>
					<text>{{item.serviceName}}</text>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '',
				tabList: [],
				activeIndex: 0,
				cateList: [],
				show: false,
				searchList: []
			};
		},
		onLoad() {
			this.getTab()
			this.getCate()
		},
		methods:{
			submit(){
				this.show = true
				this.getSearch()
			},
			getTab(){
				this.$request({
					url: '/prod-api/api/service/list'
				}).then(res => {
					console.log(res)
					this.tabList = new Set(res.rows.filter(item => item.serviceType !== null).map(item => item.serviceType))
					this.tabList = Array.from(this.tabList)
				})
			},
			tabChange(index){
				this.activeIndex = index
				this.getCate()
			},
			getCate(){
				this.$request({
					url: '/prod-api/api/service/list'
				}).then(res => {
					console.log(res)
					this.cateList = res.rows.filter(item => item.serviceType === this.tabList[this.activeIndex])
				})
			},
			getSearch(){
				this.$request({
					url: '/prod-api/api/service/list'
				}).then(res => {
					console.log(res)
					this.searchList = res.rows.filter(item => item.serviceName.includes(this.value))
				})
			}
		}
	}
</script>

<style lang="scss">
page{
	height: 100%;
	view{
		height: 100%;
		display: flex;
		flex-direction: column;
		.main{
			flex: 1;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			.left{
				width: 200rpx;
				background-color: #f7f7f7;
				.tab{
					height: fit-content;
					.tab-item{
						padding: 20rpx;
						height: 96rpx;
						color: #666;
						position: relative;
						display: flex;
						justify-content: center;
						align-items: center;
						&::before{
							position: absolute;
							content: '';
							left: 25%;
							bottom: 0;
							width: 50%;
							border-top: 2rpx solid #e4e7ed;
						}
					}
					.active{
						color: #dd6161;
						font-size: 36rpx;
						font-weight: bold;
						&::after{
							position: absolute;
							content: '';
							width: 6rpx;
							height: 100%;
							left: 0;
							top: 0;
							background-color: #dd6161;
						}
					}
				}
			}
			.right{
				flex: 1;
				.cate{
					padding: 20rpx;
					display: flex;
					flex-wrap: wrap;
					flex-direction: row;
					justify-content: start;
					height: fit-content;
					.cate-item{
						padding: 20rpx;
						width: 120rpx;
						height: fit-content;
						display: flex;
						justify-content: center;
						align-items: center;
						image{
							width: 100rpx;
							height: 100rpx;
						}
						text{
							width: 120rpx;
							white-space: nowrap;
							overflow: hidden;
							text-overflow: ellipsis;
							color: #666;
							margin-top: 10rpx;
							text-align: center;
						}
						.icon{
							width: 100rpx;
							height: 100rpx;
							display: flex;
							justify-content: center;
							align-items: center;
							border-radius: 50%;
							border: 4rpx solid #2979ff;
							color: #2979ff;
						}
					}
				}
			}
		}
		.popup{
			.cate{
				padding: 20rpx;
				display: flex;
				flex-wrap: wrap;
				flex-direction: row;
				justify-content: start;
				height: fit-content;
				.cate-item{
					padding: 20rpx;
					width: 120rpx;
					height: fit-content;
					display: flex;
					justify-content: center;
					align-items: center;
					image{
						width: 100rpx;
						height: 100rpx;
					}
					text{
						width: 120rpx;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
						color: #666;
						margin-top: 10rpx;
						text-align: center;
					}
					.icon{
						width: 100rpx;
						height: 100rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						border-radius: 50%;
						border: 4rpx solid #2979ff;
						color: #2979ff;
					}
				}
			}
		}
	}
}
</style>
